package util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
    private static final Properties props ;
    static {
        try {Class.forName("com.mysql.cj.jdbc.Driver");
            props = new Properties();
            InputStream resource = DBUtil.class
                    .getClassLoader()
                    .getResourceAsStream("db.properties");
            props.load(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }catch (ClassNotFoundException e){
            throw new RuntimeException(e);
        }
    }

    public static Connection getConn(){

        try {

            return DriverManager.getConnection(
                    props.getProperty("jdbcUrl"),
                    props.getProperty("username"),
                    props.getProperty("password")
            );
        }  catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
